﻿using InfonavaEye.model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InfonavaEye.common
{
    public class BoxModelHelper
    {
        public static BoxModel parseBoxModel(string boxModelName)
        {
            var filePath = util.FileHelper.getBaseDir() + "\\BoxModel\\" + boxModelName + ".json";
            var json = util.FileHelper.readFile(filePath);
            BoxModel model = null; 
            try
            {
                model = JsonConvert.DeserializeObject<BoxModel>(json);
            }
            catch (Exception ex) {
                Console.WriteLine("解析模板时发生错误,{0} {1}", ex.Message,ex.StackTrace);
                throw new Exception(String.Format("解析模板时发生错误,{0}",ex.Message));
            }

            //初步检查钉盒模型的配置逻辑是否有问题
            if (model.boxAreas == null || model.boxAreas.Count == 0)
            {
                throw new Exception("钉盒模板未配置任何区域");
            }

            return model;
        }
    }
}
